package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.vo.SysOssVo;
import com.ruoyi.system.service.ISysOssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 附件上传Controller
 *
 * @author ruoyi
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/system/SysOss2")
public class SysOssController2 extends BaseController {
    @Autowired
    private ISysOssService iSysOssService;

    @Log(title = "上传附件", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<SysOssVo> avatar(@RequestPart("file") MultipartFile file) {
        if (file.isEmpty()) {
            return R.fail("上传附件，请联系管理员");
        } else {
            SysOssVo oss = iSysOssService.upload(file);
            return R.ok(oss);
        }
    }
}
